<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">权限管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <!-- 表格区域 -->
      <el-table :data="dataList" style="width: 100%" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="authName" label="权限名称"></el-table-column>
        <el-table-column prop="path" label="路劲"></el-table-column>
        <el-table-column prop="level" label="权限等级">
          <template v-slot="{ row }">
            <el-tag :type="rightLevel[row.level].type">{{
              rightLevel[row.level].text
            }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 权限列表
      dataList: [],
      rightLevel: {
        0: { type: '', text: '一级' },
        1: { type: 'success', text: '二级' },
        2: { type: 'warning', text: '三级' },
        3: { type: 'danger', text: '四级' }
      }
    }
  },
  methods: {
    // 获取权限列表
    async getRightsList() {
      const { data: res } = await this.$http.get('rights/list')
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      this.dataList = res.data
      this.$message.success(res.meta.msg)
    }
  },
  created() {
    // 获取权限列表
    this.getRightsList()
  }
}
</script>

<style lang='less' scoped>
.el-breadcrumb {
  margin-bottom: 20px;
}
</style>
